package com.javaeedev.lightweight.mvc.sample.web;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.javaeedev.lightweight.mvc.Action;
import com.javaeedev.lightweight.mvc.ActionContext;
import com.javaeedev.lightweight.mvc.Model;

/**
 * Test inject array values via request.getParameterValues() method.
 * 
 * @author Xuefeng
 */
public class TestArrayAction implements Action {

    private Log log = LogFactory.getLog(getClass());

    public void setIntArray(Integer[] array) {
        log.info("Inject Integer[]: " + arrayToString(array));
    }

    public void setStringArray(String[] array) {
        log.info("Inject String[]: " + arrayToString(array));
    }

    String arrayToString(Object[] array) {
        if(array.length==0)
            return "";
        StringBuilder sb = new StringBuilder(128);
        for(Object o : array) {
            sb.append(o).append(",");
        }
        sb.deleteCharAt(sb.length()-1);
        return sb.toString();
    }

    public Model execute() throws Exception {
        ActionContext.getActionContext().getResponse().getWriter().println("Please check log in console.");
        return null;
    }

}
